#include "Setting_Feedback.h"
#include <QApplication>

namespace UserManagementSystem {
Setting_Feedback::Setting_Feedback(QWidget *parent)
    : QWidget{parent}
{
    qDebug()<<__FUNCTION__;

    m_mainLayout=new QVBoxLayout(this);

    m_contentWidget=new QWidget();
    m_scrollArea=new QScrollArea();
    m_scrollArea->setAlignment(Qt::AlignLeft);
    m_scrollArea->setWidgetResizable(true);
    m_scrollArea->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
    m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

    m_contentLayout=new QVBoxLayout(m_contentWidget);
    m_contentLayout->setContentsMargins(5,5,5,5);

    m_descriptionInput=new BasePlainTextEdit();

    m_contactInput=new QLineEdit();

    m_uploadWidget=new UploadPictures();

    m_chooseAttachment=new QComboBox();

    m_approvalBtn=new QCheckBox();

    m_sendBtn=new QPushButton();



    m_sendBtn->setText(tr("发送"));
    m_chooseAttachment->setEditText(tr("请选择"));

    InitDefaultLayout();
}

void Setting_Feedback::InitDefaultLayout()
{
    m_contactInput->setFixedHeight(40);


    m_contentLayout->addWidget(&m_label_1);
    m_contentLayout->addWidget(m_descriptionInput);
    m_contentLayout->addSpacing(10);

    m_contentLayout->addWidget(&m_label_2);
    m_contentLayout->addWidget(m_contactInput);
    m_contentLayout->addSpacing(10);

    m_contentLayout->addWidget(&m_label_3);
    m_contentLayout->addWidget(&m_label_4);
    m_contentLayout->addWidget(m_uploadWidget);
    m_contentLayout->addSpacing(10);

    m_contentLayout->addWidget(&m_label_5);
    m_contentLayout->addWidget(m_chooseAttachment);
    m_contentLayout->addSpacing(10);

    m_contentLayout->addWidget(&m_label_6);

    QHBoxLayout* sub_layout_1=new QHBoxLayout();
    sub_layout_1->addWidget(m_approvalBtn);
    sub_layout_1->addWidget(&m_label_7);
    sub_layout_1->addStretch(1);
    m_contentLayout->addLayout(sub_layout_1);

    QHBoxLayout* sub_layout_2=new QHBoxLayout();
    sub_layout_2->addStretch(1);
    sub_layout_2->addWidget(m_sendBtn);
    m_contentLayout->addLayout(sub_layout_2);



    m_scrollArea->setWidget(m_contentWidget);

    m_mainLayout->addWidget(m_scrollArea);

    InitDefaultStyle();

}

void Setting_Feedback::InitDefaultStyle()
{

    m_contactInput->setPlaceholderText(tr("手机/邮箱"));

    m_label_2.setText(tr("联系方式"));
    m_label_4.setText(tr("支持格式 JPG,JEPG，PNG,MP4，AVI,WMV"));
    m_label_5.setText(tr("附件"));
    m_label_6.setText(tr("提交反馈时会包括软件版本号，操作系统以及CPU,内存，显卡等信息，所有提交信息将会加密"));

    this->SetLabelFullText(&m_label_1,tr("描述*"),false);
    this->SetLabelFullText(&m_label_3,tr("请上传视频或图片*"),false);
    this->SetLabelFullText(&m_label_7,tr("* 我同意将原始扫描数据及相关信息发送给Aidite服务团队"),true);

    QString label_style=(R"(
        font-size:10pt; font-weight: bold;
    )");
    m_label_1.setStyleSheet(label_style);
    m_label_2.setStyleSheet(label_style);
    m_label_3.setStyleSheet(label_style);
    m_label_5.setStyleSheet(label_style);

    QString label_gray_style=(R"(
        color:gray;
        font-size:9pt;
    )");
    m_label_4.setStyleSheet(label_gray_style);
    m_label_6.setStyleSheet(label_gray_style);
    m_label_7.setStyleSheet(label_gray_style);
    //浅蓝色窗口 样式

    m_contactInput->setStyleSheet(R"(

    QLineEdit{
        background-color: #f7f9fb;
        border: 1px solid #f7f9fb;
        border-radius: 6px;
        padding:5px;
    }
    QLineEdit::hover{
        border: 1px solid #4672C4;
    }
)");
    m_chooseAttachment->setStyleSheet(R"(
        background-color: white;
        border: 1px solid gray;
        border-radius: 5px;
    )");

    //scrollarea样式
    //滚动条样式
    QString scroll_sty=(R"(
    QScrollArea{
        border:none;
    }

    QScrollArea  QScrollBar:vertical,QScrollArea  QScrollBar:horizontal {
        background-color: white;
        width: 4px;
        margin: 0px 0px 0px 0px;
    }

    QScrollArea QScrollBar::handle:vertical,QScrollArea QScrollBar::handle:horizontal {
        background: gray;
        height: 6px;
        width: 4px;
        border-radius: 2px;
    }

    QScrollArea QScrollBar::sub-line, QScrollArea  QScrollBar::add-line,
    QScrollArea QScrollBar::up-arrow, QScrollArea  QScrollBar::down-arrow:vertical {
        height: 0px;
    }
)");

    m_scrollArea->setStyleSheet(scroll_sty);
    m_contentWidget->setStyleSheet("background-color:white");

    //发送按钮的样式
    m_sendBtn->setStyleSheet(R"(

    QPushButton{
        border:1px solid #4672C4;
        height:30px;
        width:70px;
        border-radius:15px;
        background-color:white;
        color:#4672C4;
    }
    QPushButton::hover{
        background-color:#4672C4;
        color:white;
    }

)");


    //附件的样式
    QString arrow_icon_path=QApplication::applicationDirPath()+"/res/PatientManager/lower_arrow.png";

    QString Combobox_style=QString(R"(
    QComboBox {
        padding-right: 30px;
        padding-left: 10px;
        height: 30px;
        color:gray;
        border-radius: 5px;
        border: 1px solid gray;
        background-color:white;
    }
    QComboBox::hover{
    border: 1px solid #4672c4;

    }

    QComboBox::drop-down {
        width: 40px;
        background-color:white;
        color: black;
        border-radius: 5px;
    }
    QComboBox::down-arrow {
        image:url(%1);
        width: 14px;
        height: 14px;
    }
    QComboBox QAbstractItemView {
        outline: none;  /* 取消焦点虚线框 */
        border: none;   /* 如果有边框，也去掉 */
    }
    QComboBox QAbstractItemView::item {
        background-color: white;
        height: 30px;
        border-radius:5px;
        color: black;
    }
    QComboBox QAbstractItemView::item:hover {
        background-color: #4672c4;
        color: white;
        border-radius:5px;
    }
    QComboBox QAbstractItemView QScrollBar:vertical {
        background: transparent;
        width: 2px;
        margin: 0px 0px 0px 0px;
    }
    QComboBox QAbstractItemView QScrollBar::handle:vertical {
        background: gray;
        height: 3px;
        width: 2px;
        border-radius: 2px;
    }
    QComboBox QAbstractItemView QScrollBar::sub-line, QScrollBar::add-line,
    QScrollBar::up-arrow,QScrollBar::down-arrow:vertical {
        height: 0px;
    }


)").arg(arrow_icon_path);


    m_chooseAttachment->setStyleSheet(Combobox_style);

}

void Setting_Feedback::SetLabelFullText(QWidget *label, const QString &text,const bool is_front)
{

    //将传入的字符串设置为前半部分和后半部分
    QString front,tail;
    if(!is_front){
        front=text.left(text.size()-1);
        tail=text.right(1);
        QLabel* new_label=dynamic_cast<QLabel*>(label);

        new_label->setText(front + "<span style='color:red;'>" + tail + "</span>");

    }else{
        front=text.left(1);
        tail=text.right(text.size()-1);
        QLabel* new_label=dynamic_cast<QLabel*>(label);
        new_label->setText("<span style='color:red;'>"+front +"</span>" + tail );
    }
}

}
